package LoginUtil;


import java.util.Date;

/**
 * Our datastore user superclass
 * @author Win Nadeau
 */
public class User {
	public static enum UserType {
		Patient,
		Doctor,
		Nurse,
		Admin,
		Invalid
	}
	
	/**
	 * a unique email address
	 */
	private String username;
	/**
	 * a password with certain TBD constraints
	 */
	private String password;
	/**
	 * date created/joined
	 */
	private Date creationDate;
	/**
	 * no constraints
	 */
	private String firstName;
	private String lastName;
	
	/**
	 * What class of user this user is
	 */
	private UserType type;
	
	/**
	 * if the user is a valid user in the database - used for queries
	 */
	private boolean valid;
	
	/**
	 * if the user account is suspended because of 3 incorrect password attempts
	 */
	private boolean suspended;
	
	/**
	 * number of consecutive invalid login attempts
	 */
	private int loginAttempts;
 
	/**
	 * constructor that validates username/password 
	 * @param username must be a valid email address
	 * @param password must be more than 5 characters for now
	 */
	public User (String username, String password){
		/**
		 * TODO: REGEX this shit for validation
		 */
		this.username = username;
		this.password = password;
	}
	
	// the following protected constructors and methods are for db querying
	
	public User() {
		
	}	

	public void setUsername(String username) {
		this.username = username;
	}	
	public void setPassword(String password) {
		this.password = password;
	}	
	protected void setCreationDate(Date date) {
		this.creationDate = date;
	}
	public String getPassword() {
		return this.password;
	}
	
	//TODO create constructor chain for other data fields, like name and anything else we'll add
	public Date getCreationDate() {
		return creationDate;
	}
	/**
	 * This is how the server will validate users easily
	 * @param passwordAttempt
	 * @return true only if the strings match exactly
	 */
	public boolean passwordCheck(String passwordAttempt){
		if (this.password.equals(passwordAttempt)){
			return true;
		}
		return false;
	}
	public void setFirstName(String name) {
		this.firstName = name;
	}
	public String getFirstName() {
		return firstName;
	}
	public void setLastName(String name) {
		this.lastName = name;
	}
	public String getLastName() {
		return lastName;
	}
	public String getUsername() {
		return username;
	} 
	public void setUserName(String name) {
		this.username = name;
	}
	public void setValid(boolean valid) {
		this.valid = valid;
	}
	public boolean isValid() {
		return valid;
	}
	public void setUserType(UserType type) {
		this.type = type;
	}
	public UserType getUserType() {
		return this.type;
	}
	
	public boolean isSuspended() {
		return suspended;
	}

	public void setSuspended(boolean suspended) {
		this.suspended = suspended;
	}

	public int getLoginAttempts() {
		return loginAttempts;
	}

	public void setLoginAttempts(int loginAttempts) {
		this.loginAttempts = loginAttempts;
	}
	
	/**
	 * increment the number of times an user has unsuccessfully logged in
	 * @return
	 * 		the incremented number
	 */
	public int incLoginAttempts() {
		return ++this.loginAttempts;
	}

}
